<template>
  <div><el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
  >
  <span> <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="楼栋名称">
      <el-input v-model="form.name"></el-input>
    </el-form-item>
 <el-form-item label="所属园区">
    <el-select v-model="form.area" placeholder="请选择所属园区">
      <el-option v-for="area in areaList" :key="area.id" :label="area.name" :value="area.id"></el-option>
    </el-select>
  </el-form-item>
      <el-form-item label="楼栋类别">
    <el-select v-model="form.type" placeholder="请选择楼栋类别">
      <el-option label="男" value="男"></el-option>
      <el-option label="女" value="女"></el-option>
    </el-select>
  </el-form-item>
    <el-form-item label="最大层数">
      <el-input v-model="form.maxFloor"  disabled></el-input>
    </el-form-item>
  </el-form></span>

    <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="submit">确 定</el-button>
  </span>
  </el-dialog></div>
</template>
<script>
import {_searchAreaByName, _buildingModify} from '../../../../api/super_admin'

export default {
  name: 'BuildingEditDialog',
  created () {
    const DOT = {
      pageSize: 10000,
      pageNo: 1,
      data: {name: ''}
    }
    _searchAreaByName(DOT).then(res => {
      if (res.status) {
        this.areaList = res.data
      } else {
        this.$message({
          message: res.message,
          type: 'error'
        })
      }
    })
  },
  data () {
    return {
      dialogVisible: false,
      areaList: [],
      form: {
        name: '',
        type: '',
        max_floor: 10,
        areaName: '',
        area: null
      }
    }
  },
  methods: {
    show (Building) {
      this.dialogVisible = true
      this.form = JSON.parse(JSON.stringify(Building))
    },
    submit () {
      const OBJ = JSON.parse(JSON.stringify(this.form))
      delete OBJ.areaName
      for (let item in OBJ) {
        if (item === '') {
          this.$message({
            message: '所有字段非空',
            type: 'error'
          })
          return
        }
      }
      _buildingModify(OBJ).then(res => {
        if (res.status) {
          this.$message({
            message: '修改成功',
            type: 'success'
          })
          this.dialogVisible = false
          this.$emit('ok')
        } else {
          this.$message({
            message: '修改失败',
            type: 'warning'
          })
        }
      })
    }
  }
}
</script>
<style scoped>

</style>
